//
//  PickCarCell.m
//  Zhiche-Carriage
//
//  Created by 王亚陆 on 16/6/16.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "PickCarCell.h"
#import <Masonry.h>
@implementation PickCarCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 30*kHeight)];
        self.view.backgroundColor = RGBACOLOR(149, 149, 149, 0.2);
        self.number = [self createUIlabel:@"运单号:" andFont:FontOfSize14 andColor:BlackColor];
        self.orderNumber = [self createUIlabel:@"zc2713474894834747" andFont:FontOfSize14 andColor:BlackColor];
        
        self.time = [self createUIlabel:@"20分钟" andFont:FontOfSize14 andColor:BlackColor];
        [self.view addSubview:self.number];
        [self.view addSubview:self.orderNumber];
        [self.view addSubview:self.time];
        [self.contentView addSubview:self.view];
        
        [self.number mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.view.mas_left).with.offset(14*kWidth);
            make.centerY.mas_equalTo(self.view.mas_centerY);
        }];
        [self.orderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.number.mas_right).with.offset(10*kWidth);
            make.centerY.mas_equalTo(self.view.mas_centerY);
        }];
        [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.view.mas_right).with.offset(-14*kWidth);
            make.centerY.mas_equalTo(self.view.mas_centerY);
        }];
        
        self.scrollView = [[UIScrollView alloc]init];
        self.scrollView.contentSize = CGSizeMake(screenWidth + 150*2*kWidth, 20*kHeight);
        self.scrollView.alwaysBounceHorizontal = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        [self.contentView addSubview:self.scrollView];
        
        self.carStyle = [self createUIlabel:@"" andFont:FontOfSize14 andColor:BlackColor];
        [self.scrollView addSubview:self.carStyle];
        //省市县
        self.startAddress = [self createUIlabel:@"长沙" andFont:FontOfSize14 andColor:BlackColor];
        //发车单位 收车单位
        self.startDetailAddress = [self createUIlabel:@"长沙芒果库" andFont:FontOfSize14 andColor:BlackColor];
        self.startTimeL = [self createUIlabel:@"2016-01-09" andFont:FontOfSize14 andColor:BlackColor];
        self.endAddress = [self createUIlabel:@"湖南" andFont:FontOfSize14 andColor:BlackColor];
        self.endDetailAddress = [self createUIlabel:@"湖南益阳宝马4S店" andFont:FontOfSize14 andColor:BlackColor];
        self.endTimeL = [self createUIlabel:@"2016-01-20" andFont:FontOfSize14 andColor:BlackColor];
        [self.contentView addSubview:self.startAddress];
        [self.contentView addSubview:self.startDetailAddress];
        [self.contentView addSubview:self.startTimeL];
        [self.contentView addSubview:self.endAddress];
        [self.contentView addSubview:self.endDetailAddress];
        [self.contentView addSubview:self.endTimeL];
        
        [self.startAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView.mas_left).with.offset(Main_Width/4*kHeight);
            make.top.mas_equalTo(self.view.mas_bottom).with.offset(10*kHeight);
        }];
        
        [self.startDetailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.startAddress.mas_centerX);
            make.top.mas_equalTo(self.startAddress.mas_bottom).with.offset(10*kHeight);
        }];
        [self.startTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.startAddress.mas_centerX);
            make.top.mas_equalTo(self.startDetailAddress.mas_bottom).with.offset(10*kHeight);
        }];
        [self.endAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView.mas_right).with.offset(-Main_Width/4*kHeight);
            make.top.mas_equalTo(self.view.mas_bottom).with.offset(10*kHeight);
        }];
        [self.endDetailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.endAddress.mas_centerX);
            make.centerY.mas_equalTo(self.startDetailAddress.mas_centerY);
        }];
        [self.endTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.endDetailAddress.mas_centerX);
            make.centerY.mas_equalTo(self.startTimeL.mas_centerY);
        }];
        _RightBtn = [self createBtn:@"前往提车"];
        [self.contentView addSubview:_RightBtn];

    }
    return self;
}

-(void)showInfo:(NSDictionary *)dic_info
{

    self.time.text =[NSString stringWithFormat:@"%@",dic_info[@"statusText"]];
        
    self.orderNumber.text = [NSString stringWithFormat:@"%@", dic_info[@"orderCode"]];
    NSString * startAddress = [NSString stringWithFormat:@"%@",dic_info[@"departCityName"]];
    self.startAddress.text = startAddress;//省市县
    self.startDetailAddress.text = [NSString stringWithFormat:@"%@",dic_info[@"departUnit"]];//发车单位
    self.startTimeL.text = [NSString stringWithFormat:@"%@", dic_info[@"deliveryDate"]];//发车时间
    NSString * endAddress = [NSString stringWithFormat:@"%@",dic_info[@"receiptCityName"]];
    self.endAddress.text = endAddress;//省市县
    self.endDetailAddress.text =  [NSString stringWithFormat:@"%@",dic_info[@"receiptUnit"]];//收车单位
    self.endTimeL.text = [NSString stringWithFormat:@"%@",dic_info[@"arriveDate"]];//到达时间
    
    UIImageView * imageline =[[UIImageView alloc]init];
    imageline.image = [UIImage imageNamed:@"common_list_line1"];
    [self.contentView addSubview:imageline];
    [imageline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(self.endTimeL.mas_bottom).with.offset(5*kHeight);
    }];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageline.mas_bottom).offset(5*kHeight);
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(screenWidth, 20*kHeight));
    }];
    UIImageView * imageline1 =[[UIImageView alloc]init];
    imageline1.image = [UIImage imageNamed:@"common_list_line1"];
    [self.contentView addSubview:imageline1];
    [imageline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(0);
        make.size.mas_equalTo(CGSizeMake(Main_Width, 0.5));
        make.top.mas_equalTo(self.scrollView.mas_bottom).with.offset(5*kHeight);
    }];
    
    
    int stute = [dic_info[@"status"] intValue];
    if (stute == 40) {
        [_RightBtn setTitle:@"前往提车" forState:UIControlStateNormal];
    }
    else if (stute == 45 ){
        [_RightBtn setTitle:@"现场提车" forState:UIControlStateNormal];
    }
    else{
        [_RightBtn setTitle:@"送达交车" forState:UIControlStateNormal];
    }
    
    
    
    
    
    NSMutableArray * carstyle = dic_info[@"vehicles"];
    NSString * carName = [[NSString alloc]init];
    for (int i=0; i<carstyle.count; i++) {
        carName = [carName stringByAppendingString:[NSString stringWithFormat:@"%@ ",carstyle[i][@"vehicleName"]]];
    }
    self.carStyle.text = carName;
    [self.carStyle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.scrollView.mas_left).with.offset(0);
        make.centerY.mas_equalTo(self.scrollView.mas_centerY);
    }];
    NSLog(@"%f",self.carStyle.frame.size.width);
    self.scrollView.contentSize = CGSizeMake(self.carStyle.frame.size.width, 20*kHeight);
    
    [_RightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(-20*kWidth);
        make.size.mas_equalTo(CGSizeMake(Main_Width/3, 35*kHeight));
        make.top.mas_equalTo(self.scrollView.mas_bottom).with.offset(10*kHeight);
    }];

        
    
    
    
}

-(NewBtn*)createBtn:(NSString*)title {
    
    NewBtn * btn = [NewBtn buttonWithType:UIButtonTypeCustom];
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = RGBACOLOR(149, 149, 149, 1).CGColor;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:BlackColor forState:UIControlStateNormal];
    btn.titleLabel.font = Font(FontOfSize14);
    
    return btn;
}

-(UILabel*)createUIlabel:(NSString *)title andFont:(CGFloat)font andColor:(UIColor*)color {
    UILabel * label =[[UILabel alloc]init];
    label.text = title;
    label.textColor = color;
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:font];CGSize size = [label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    CGFloat nameH = size.height;
    CGFloat nameW = size.width;
    label.textAlignment = NSTextAlignmentRight;
    label.frame =CGRectMake(0, 0, nameW, nameH);
    label.font = Font(font);
    return label;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
